package com.solo.system.web;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.mybatisflex.core.query.QueryWrapper;
import com.solo.common.core.global.R;
import com.solo.system.model.notice.resp.NoticeUserListResp;
import com.solo.system.service.SysNoticeUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.solo.system.api.entity.table.SysNoticeUserTableDef.SysNoticeUserTable;
import static com.solo.system.api.entity.table.SysUserTableDef.SysUserTable;

/**
 * 通知公告用户关联控制器
 * @author 十一
 * @since 2024-12-04 14:28
 * 人生若只如初见，何事秋风悲画扇
 **/
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/notice-user")
public class SysNoticeUserController {

    private final SysNoticeUserService sysNoticeUserService;

    /**
     * 接收人列表
     * @param noticeId 通知id
     * @return {@link R }<{@link List }<{@link NoticeUserListResp }>>
     */
    @GetMapping("/list/{noticeId}")
    @SaCheckPermission("system-notice-query")
    public R<List<NoticeUserListResp>> list(@PathVariable("noticeId") Long noticeId) {
        QueryWrapper qw = QueryWrapper.create()
                .select(SysNoticeUserTable.UserId, SysUserTable.Name, SysNoticeUserTable.IsRead)
                .from(SysNoticeUserTable)
                .leftJoin(SysUserTable).on(SysNoticeUserTable.UserId.eq(SysUserTable.UserId))
                .where(SysNoticeUserTable.NoticeId.eq(noticeId));
        return R.success(sysNoticeUserService.listAs(qw, NoticeUserListResp.class));
    }

}
